<template>
  <a-card :bordered="false" :class="'cust-erp-sub-tab'">
<!--    图表-->
    <div v-if="countSourceList.length>0">
    <a-select v-model="selectkey" style="width:600px" @change="handleChartChange">
      <a-select-option v-for="(item,index) in countSourceList" :value="index">
        {{item.label}}
      </a-select-option>
    </a-select>
<!--    <pie class="statistic" :title="countSource.label" :dataSource="countSource.data" :height="450"/>-->
<!--      <radar class="statistic" :title="countSource.label" :dataSource="countSource.data" :height="450"/>-->
<!--      <rank-list class="statistic" :title="countSource.label" :list="countSource.data" :height="450"/>-->
      <bar class="statistic" :title="countSource.label" :dataSource="countSource.data" :height="450"/>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="mainId">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('表单数据')">导出</a-button>
<!--      <a-upload-->
<!--        name="file"-->
<!--        :showUploadList="false"-->
<!--        :multiple="false"-->
<!--        :headers="tokenHeader"-->
<!--        :action="importExcelUrl"-->
<!--        @change="handleImportExcel">-->
<!--          <a-button type="primary" icon="import">导入</a-button>-->
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <a @click="handleEdit(record)">编辑</a>-->
          <a @click="handleDesignFormDataModal(record)">查看</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <lbDesformData-modal ref="modalForm" @ok="modalFormOk" :mainId="mainId"></lbDesformData-modal>
    <DesignFormDataModal ref="designFormDataModal" @ok="modalFormOk" :mainId="mainId"></DesignFormDataModal>
  </a-card>
</template>

<script>
  import { getAction,postAction,putAction } from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LbDesformDataModal from './modules/LbDesformDataModal'
  import DesignFormDataModal from './modules/DesignFormDataModal'
  import Pie from '@/components/chart/Pie'
  import Radar from '@/components/chart/Radar'
  import RankList from '@/components/chart/RankList'
  import Bar from '@/components/chart/Bar'
  export default {
    name: "LbDesformDataList",
    mixins:[JeecgListMixin],
    components: { DesignFormDataModal, LbDesformDataModal,Pie,Radar,RankList,Bar},
    props:{
      mainId:{
        type:String,
        default:'',
        required:false
      }
    },
    watch:{
      mainId:{
        immediate: true,
        handler(val) {
          if(!this.mainId){
            this.clearList()
          }else{
            this.queryParam['desformId'] = val
            this.loadData(1);
            this.getListLbDesformDataChartByMainId();
          }
        }
      }
    },
    data () {
      return {
        description: '动态表单管理页面',
        disableMixinCreated:true,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          // {
          //   title:'表单id',
          //   align:"center",
          //   dataIndex: 'desformId'
          // },
          // {
          //   title:'表单编码',
          //   align:"center",
          //   dataIndex: 'desformCode'
          // },
          {
            title:'表单名称',
            align:"center",
            dataIndex: 'desformName'
          },
          // {
          //   title:'表单数据json',
          //   align:"center",
          //   dataIndex: 'desformDataJson'
          // },
          // {
          //   title:'onlineFormCode',
          //   align:"center",
          //   dataIndex: 'onlineFormCode'
          // },
          // {
          //   title:'onlineFormDataId',
          //   align:"center",
          //   dataIndex: 'onlineFormDataId'
          // },
          {
            title:'创建时间',
            align:"center",
            sorter: true,
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/desform/lbDesform/listLbDesformDataByMainId",
          listLbDesformDataChartByMainId: "/desform/lbDesform/listLbDesformDataChartByMainId",
          delete: "/desform/lbDesform/deleteLbDesformData",
          deleteBatch: "/desform/lbDesform/deleteBatchLbDesformData",
          exportXlsUrl: "/desform/lbDesform/exportLbDesformData",
          importUrl: "/desform/lbDesform/importLbDesformData",
        },
        // 数据集
        countSourceList: [],
        countSource: [],
        selectkey:0,
        dictOptions:{
         desformType:[],
         status:[],
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl(){
        return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`;
      }
    },
    methods: {
      clearList(){
        this.dataSource=[]
        this.selectedRowKeys=[]
        this.ipagination.current = 1
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'desformName',text:'表单名称',dictCode:''})
        fieldList.push({type:'string',value:'desformType',text:'表单类型',dictCode:'lb_desform_type,title,code'})
        fieldList.push({type:'string',value:'desformCode',text:'表单模板编码',dictCode:''})
        fieldList.push({type:'string',value:'desformDesignJson',text:'表单设计json',dictCode:''})
        fieldList.push({type:'string',value:'desformIcon',text:'表单图标',dictCode:''})
        fieldList.push({type:'datetime',value:'startTime',text:'开始时间'})
        fieldList.push({type:'datetime',value:'endTime',text:'结束时间'})
        fieldList.push({type:'string',value:'parentCode',text:'父级编码',dictCode:''})
        fieldList.push({type:'string',value:'parentId',text:'父级id',dictCode:''})
        fieldList.push({type:'string',value:'status',text:'状态',dictCode:'state,,'})
        fieldList.push({type:'datetime',value:'createTime',text:'创建时间'})
        this.superFieldList = fieldList
      },
      handleDesignFormDataModal(record){
        this.$refs.designFormDataModal.edit(record);
        this.$refs.designFormDataModal.disableSubmit = false;
      },
      getListLbDesformDataChartByMainId(){
          var params = this.getQueryParams();
          const that=this ;
        that.countSourceList=[];
          getAction(this.url.listLbDesformDataChartByMainId, params).then((res) => {
            if (res.success) {
              that.countSourceList= res.result;
              that.setSource(that.countSourceList[0]);
            }
          })
      },
      handleChartChange(value) {
        this.selectkey=value;
        this.setSource(this.countSourceList[this.selectkey]);
      },
      setSource(list){
        this.countSource=this.countSourceList[this.selectkey];
        for (let i = 0; i <this.countSource.data.length; i++) {
          // this.countSource.data[i].score=this.countSource.data[i].value;
          // this.countSource.data[i].total=this.countSource.data[i].value;
          // this.countSource.data[i].total=this.countSource.data[i].value;
          // this.countSource.data[i].name=this.countSource.data[i].item;
          this.countSource.data[i].x=this.countSource.data[i].item;
          this.countSource.data[i].y=this.countSource.data[i].value;

        }


      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
  .statistic {
    padding: 0px !important;
    margin: 20px auto;
  ;
    /*padding: 10px 10px;*/
  }
</style>
